package com.moonstar.controller;

import com.moonstar.pojo.MessageDO;
import com.moonstar.pojo.Result;
import com.moonstar.pojo.User;
import com.moonstar.service.MessageService;
import com.moonstar.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {

    @Autowired
    private MessageService messageService;

    @Autowired
    private UserService userService;

    @GetMapping("/list/{id}/{toName}")
    public Result list(@PathVariable Long id, @PathVariable String toName){
//        HashMap<String, Object> map = new HashMap<>();
//        map.put("userId", id);
//        map.put("toName", toName);
//        List<MessageDO> list = messageService.list(map);
        User toUser = userService.getByUsername(toName);
        List<MessageDO> messageDOList = messageService.query(id, toUser.getId());
        return Result.success(messageDOList);
    }
}
